<template>
  <div>
      <a-table 
        :columns="columns" 
        :dataSource="tableData" 
        :rowKey="record=>record.id"
        :row-selection="rowSelection"
        >

      </a-table>
  </div>
</template>

<script>
export default {
    data(){
        return {
            columns:[
                {
                    title:'商品名称',
                    dataIndex:'goodsName',
                }
            ],
            tableData:[
                {
                    id:1,
                    goodsName:'aaa',
                },
                {
                    id:2,
                    goodsName:'bbbb',
                },
                {
                    id:3,
                    goodsName:'cccc',
                },
                {
                    id:4,
                    goodsName:'ddd',
                },
                {
                    id:5,
                    goodsName:'eee',
                },
            ],
            rowSelection:{
                type:'checkbox',
                selections:false,
                getCheckboxProps:(record)=>{
                    return {
                        props:{
                            disabled:record.disabled
                        }
                    }
                },
                onSelect:(selectedRow,isSelected,selectedRows)=>{
                    console.log(selectedRow,isSelected,selectedRows)
                    let ids=this.getAllIds(selectedRows);
                    console.log(ids);
                    if(selectedRows.length>2){
                        this.tableData.forEach(item=>{
                            item.disabled=true;
                        });
                    }
                    console.log(this.tableData);
                    // this.getCheckboxProps=(record)=>{
                    //     return {
                    //         props:{
                    //             disabled:record.disabled
                    //         }
                    //     }
                    // }
                }
            }
        }
    },
    created(){
        //this.getList();
    },
    methods:{
        async getList(){
            let res=await this.$get('/goods/page');
            if(res && res.returnCode=='1000'){
                this.tableData=res.dataInfo.records;
            }
        },
        getAllIds(data){
            return data.map(item=>{
                return item.id;
            });
        }
    }
}
</script>

<style>

</style>